package org.ws.task.event.support;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.ws.task.event.DefaultEventBusHolder;
import org.ws.task.event.EventBusHolder;
import org.ws.task.event.EventListener;
import org.ws.task.event.support.startup.BootstrapEvent;

public class BootstrapEventHolder implements EventBusHolder<BootstrapEvent> {

    private static Logger log = LoggerFactory.getLogger(BootstrapEventHolder.class.getName());

    private static final BootstrapEventHolder instance = new BootstrapEventHolder();

    private final DefaultEventBusHolder<BootstrapEvent> eventBusHolder;

    public static BootstrapEventHolder getInstance() {
        return instance;
    }

    private BootstrapEventHolder(){
        this.eventBusHolder = new DefaultEventBusHolder("BootstrapEventBus");
    }

    @Override
    public void registerListener(EventListener<BootstrapEvent> listener) {
        this.eventBusHolder.registerListener(listener);
    }

    @Override
    public void publishEvent(BootstrapEvent event) {
        log.info("BootstrapEvent:--[{}][{}]--",event.getEventType().name(),event.getIndex());
        log.debug("EventSource:{}",event.getSource());
        this.eventBusHolder.publishEvent(event);
    }
}
